/*
 * jxSwing Project (2014)
 * 
 * by Denilson Edinaldo Pinto
 * 
 * LGPL
 * Copyright (C) 2014
 * 
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */
package org.jxSwing.component.comboBox;

import java.awt.Dimension;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;

/**
 * @author Denilson Edinaldo Pinto
 * @porject jxSwing
 * @package org.jxSwing.component.comboBox
 * @date 11/05/2014 - 19:23:19
 */
public class YearComboBox extends ComboBox<Integer> {
	
	private static final long serialVersionUID = -4911927647387367062L;
	
	private final Calendar calendar = Calendar.getInstance();
	
	/**
	 * 
	 */
	public YearComboBox() {
	
		super(getYear());
		
		setSize(new Dimension(80, 25));
		setPreferredSize(new Dimension(80, 25));
		
		setSelectedNow();
	}
	
	/**
	 * @return List< Year >
	 */
	private static List<Integer> getYear() {

		final Calendar CALENDAR = Calendar.getInstance();
		
		final List<Integer> year = new ArrayList<>();
		
		// 
		for(int yearCount = CALENDAR.get(Calendar.YEAR) - 100; yearCount <= CALENDAR.get(Calendar.YEAR) + 100; yearCount++) {
			
			year.add(yearCount);
		}
		
		return year;
	}
	
	/**
	 * @param calendar
	 */
	public final void setSelectedItem(Calendar calendar) {
	
		setSelectedItem(calendar.get(Calendar.YEAR));
	}
	
	/**
	 * 
	 */
	public final void setSelectedNext() {
	
		calendar.add(Calendar.YEAR, 1);
		
		setSelectedItem(calendar);
	}
	
	/**
	 * 
	 */
	public final void setSelectedNow() {
	
		setSelectedItem(calendar);
	}
	
	/**
	 * 
	 */
	public final void setSelectedPrevious() {
	
		calendar.add(Calendar.YEAR, -1);
		
		setSelectedItem(calendar);
	}
}
